//
//  HLSquareUserCell.m
//  YueYue
//
//  Created by hulu001 on 2023/5/31.
//

#import "HLSquareUserCell.h"

@interface HLSquareUserCell ()

@property (nonatomic, strong) UIImageView *avatarView;
@property (nonatomic, strong) UIImageView *coverView;
@property (nonatomic, strong) QMUIButton *videoButton;
@property (nonatomic, strong) UIImageView *coinView;
@property (nonatomic, strong) UILabel *priceLabel;
@property (nonatomic, strong) UILabel *unitLabel;
@property (nonatomic, strong) UILabel *nicknameLabel;

@end

@implementation HLSquareUserCell


-(instancetype)initWithFrame:(CGRect)frame{
    
    if ([super initWithFrame:frame]) {
        [self setupView];
    }
    return self;
    
}

- (void)setupView {
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = 8;
    
    self.backgroundColor = [HLMainColor colorWithAlphaComponent:0.7];
    
    self.avatarView = [[UIImageView alloc] init];
    _avatarView.contentMode = UIViewContentModeScaleAspectFill;
    _avatarView.layer.masksToBounds = YES;
    _avatarView.layer.cornerRadius = 8;
    [self.contentView addSubview:_avatarView];
    [_avatarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(3, 3, -3, -3));
    }];
    
    self.coverView = [[UIImageView alloc] initWithImage:UIImageMake(@"home_flow_cover")];
    [self.contentView addSubview:_coverView];
    [_coverView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
    }];
    
    self.videoButton = [[QMUIButton alloc] init];
    [_videoButton setImage:UIImageMake(@"square_video_icon") forState:UIControlStateNormal];
    [_videoButton addTarget:self action:@selector(videoAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_videoButton];
    [_videoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.bottom.mas_equalTo(-12);
    }];
    
    self.coinView = [[UIImageView alloc] initWithImage:UIImageMake(@"home_flow_coin")];
    [self.contentView addSubview:_coinView];
    [_coinView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.bottom.equalTo(_videoButton);
    }];
    
    self.priceLabel = [[UILabel alloc] qmui_initWithFont:UIFontBoldMake(12) textColor:UIColorWhite];
    _priceLabel.text = @"199";
    [self.contentView addSubview:_priceLabel];
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_coinView);
        make.left.equalTo(_coinView.mas_right).offset(2);
    }];
    
    self.unitLabel = [[UILabel alloc] qmui_initWithFont:UIFontMake(8) textColor:[UIColorWhite colorWithAlphaComponent:0.7]];
    _unitLabel.text = @"/分钟";
    [self.contentView addSubview:_unitLabel];
    [_unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_priceLabel);
        make.left.equalTo(_priceLabel.mas_right).offset(2);
    }];
    
    self.nicknameLabel = [[UILabel alloc] qmui_initWithFont:UIFontMediumMake(14) textColor:UIColorWhite];
    _nicknameLabel.text = @"123";
    [self.contentView addSubview:_nicknameLabel];
    [_nicknameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_coinView);
        make.bottom.equalTo(_coinView.mas_top).offset(-4);
    }];
}

- (void)setModel:(HLSquareUserModel *)model
{
    _model = model;
    [_avatarView sd_setImageWithURL:[NSURL URLWithString:model.flashChatCover] placeholderImage:[HLUIHelper avatarBigPlaceholder]];
    _priceLabel.text = model.videoPrice;//[NSString stringWithFormat:@"%ld", [model.videoUnitPrice integerValue]];
    NSString *name = model.nickName;
    if (name.length > 4){
       name = [NSString stringWithFormat:@"%@...", [model.nickName substringWithRange:NSMakeRange(0, 4)]];
    }
    if (model.age.length > 0){
        name = [NSString stringWithFormat:@"%@·%@岁", name, model.age];
    }
    _nicknameLabel.text = name;
}

- (void)videoAction:(QMUIButton *)btn
{
    HLUserInfoModel *user = [[HLUserInfoModel alloc] init];
    user.userId = _model.customerId;
    user.videoType = [_model videoType];
    [HLUIHelper callWithUser:user];
}

@end
